﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using MetroFramework.Forms;
using System.IO;

namespace WinForm_运动控制demo
{
    public partial class Form1 : MetroForm
    {
        public Form1()
        {
            InitializeComponent();
            this.BorderStyle = MetroFormBorderStyle.FixedSingle;
            this.ShadowType = MetroFormShadowType.AeroShadow;
        }
        private string [] tab_str = { "WinForm_Ctrl_IO", "WinForm_DAC", "WinForm_JOG", "WinForm_PV", "WinForm_Home", "WinForm_MPG", "WinForm_Crd" };
        private string path = null;
        private string open_exe(int index)
        {
            string str = path + "\\exe\\" + tab_str[index-1] + "\\" + tab_str[index - 1] + ".exe";
            return str;
        }
        private string open_pdf(int index)
        {
            string str = path + "\\pdf\\" + tab_str[index - 1] + ".pdf"; ;
            return str;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //string pathstr = System.Environment.CurrentDirectory + "\\exe\\" + "WinForm_Crd\\WinForm_Crd.exe";
            Process f = Process.Start(open_exe(1));
            f.WaitForExit();
            //if (f.ExitCode!= 0)
            //{
            //    Console.WriteLine("执行失败！");
            //    return;
            //}
            //Console.WriteLine("执行成功。");
            //Console.Read();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            path = System.Environment.CurrentDirectory ;
            this.toolStripStatusLabel1.Text = "文件路径：" + path;
        }

        private void metroButton4_Click(object sender, EventArgs e)
        {
            // tab1 exe
            Process f = Process.Start(open_exe(1));
            this.toolStripStatusLabel1.Text = "打开WinForm_Ctrl_IO例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Ctrl_IO例程";
        }

        private void metroButton3_Click(object sender, EventArgs e)
        {
            //tab1 pdf
            Process f = Process.Start(open_pdf(1));
            this.toolStripStatusLabel1.Text = "打开WinForm_Ctrl_IO参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Ctrl_IO参考程序";
        }

        private void metroButton1_Click(object sender, EventArgs e)
        {
            // tab2 exe
            Process f = Process.Start(open_exe(2));
            this.toolStripStatusLabel1.Text = "打开WinForm_DAC例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_DAC例程";
        }

        private void metroButton2_Click(object sender, EventArgs e)
        {
            // tab2 pdf
            Process f = Process.Start(open_pdf(2));
            this.toolStripStatusLabel1.Text = "打开WinForm_DAC参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_DAC参考程序";
        }

        private void metroButton6_Click(object sender, EventArgs e)
        {
            //  tab3 exe
            Process f = Process.Start(open_exe(3));
            this.toolStripStatusLabel1.Text = "打开WinForm_JOG例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_JOG例程";
        }

        private void metroButton5_Click(object sender, EventArgs e)
        {
            // tab3 pdf
            Process f = Process.Start(open_pdf(3));
            this.toolStripStatusLabel1.Text = "打开WinForm_JOG参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_JOG参考程序";
        }

        private void metroButton8_Click(object sender, EventArgs e)
        {
            // tab4 exe
            Process f = Process.Start(open_exe(4));
            this.toolStripStatusLabel1.Text = "打开WinForm_PV例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_PV例程";
        }

        private void metroButton7_Click(object sender, EventArgs e)
        {
            // tab4 pdf
            Process f = Process.Start(open_pdf(4));
            this.toolStripStatusLabel1.Text = "打开WinForm_PV参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_PV参考程序";
        }

        private void metroButton10_Click(object sender, EventArgs e)
        {
            // tab5 exe
            Process f = Process.Start(open_exe(5));
            this.toolStripStatusLabel1.Text = "打开WinForm_Home例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Home例程";
        }

        private void metroButton9_Click(object sender, EventArgs e)
        {
            // tab5 pdf
            Process f = Process.Start(open_pdf(5));
            this.toolStripStatusLabel1.Text = "打开WinForm_Home参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Home参考程序";
        }

        private void metroButton12_Click(object sender, EventArgs e)
        {
            // tab6 exe
            Process f = Process.Start(open_exe(6));
            this.toolStripStatusLabel1.Text = "打开WinForm_MPG例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_MPG例程";
        }

        private void metroButton11_Click(object sender, EventArgs e)
        {
            // tab6 pdf
            Process f = Process.Start(open_pdf(6));
            this.toolStripStatusLabel1.Text = "打开WinForm_MPG参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_MPG参考程序";
        }

        private void metroButton14_Click(object sender, EventArgs e)
        {
            // tab7 exe
            Process f = Process.Start(open_exe(7));
            this.toolStripStatusLabel1.Text = "打开WinForm_Crd例程";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Crd例程";
        }

        private void metroButton13_Click(object sender, EventArgs e)
        {
            // tab7 pdf
            Process f = Process.Start(open_pdf(7));
            this.toolStripStatusLabel1.Text = "打开WinForm_Crd参考程序";
            f.WaitForExit();
            this.toolStripStatusLabel1.Text = "关闭WinForm_Crd参考程序";
        }
    }
}
